package org.seckill.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.seckill.model.Seckill;
import org.seckill.model.SeckillCriteria;

public interface SeckillMapper {
    @SelectProvider(type=SeckillSqlProvider.class, method="countByExample")
    long countByExample(SeckillCriteria example);

    @DeleteProvider(type=SeckillSqlProvider.class, method="deleteByExample")
    int deleteByExample(SeckillCriteria example);

    @Delete({
        "delete from seckill",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long seckillId);

    @Insert({
        "insert into seckill (seckill_id, name, ",
        "number, start_time, ",
        "end_time, create_time)",
        "values (#{seckillId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
        "#{number,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP}, ",
        "#{endTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(Seckill record);

    @InsertProvider(type=SeckillSqlProvider.class, method="insertSelective")
    int insertSelective(Seckill record);

    @SelectProvider(type=SeckillSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="seckill_id", property="seckillId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="number", property="number", jdbcType=JdbcType.INTEGER),
        @Result(column="start_time", property="startTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Seckill> selectByExample(SeckillCriteria example);

    @Select({
        "select",
        "seckill_id, name, number, start_time, end_time, create_time",
        "from seckill",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="seckill_id", property="seckillId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="number", property="number", jdbcType=JdbcType.INTEGER),
        @Result(column="start_time", property="startTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Seckill selectByPrimaryKey(Long seckillId);

    @UpdateProvider(type=SeckillSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Seckill record, @Param("example") SeckillCriteria example);

    @UpdateProvider(type=SeckillSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Seckill record, @Param("example") SeckillCriteria example);

    @UpdateProvider(type=SeckillSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Seckill record);

    @Update({
        "update seckill",
        "set name = #{name,jdbcType=VARCHAR},",
          "number = #{number,jdbcType=INTEGER},",
          "start_time = #{startTime,jdbcType=TIMESTAMP},",
          "end_time = #{endTime,jdbcType=TIMESTAMP},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where seckill_id = #{seckillId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Seckill record);
}